package sample.Admin;

import com.jfoenix.controls.JFXButton;
import controller.MainController;
import controller.admin.AdminAddStuController;
import controller.admin.AdminStuController;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TableView;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

import java.io.IOException;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;

public class AdminStu extends Application {
    private  FXMLLoader loader;
    public void start(Stage primaryStage) throws  Exception{
        try{
            loader = new FXMLLoader(getClass().getResource("../../fxml/admin/管理员学生管理.fxml"));
            Parent root =  loader.load();
            AnchorPane anchorPane = (AnchorPane) root;
            Stage stage = new Stage();
            Scene sc = new Scene(anchorPane,845,460);
            stage.setScene(sc);
            stage.setResizable(false);
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String dateString = "2021-5-31 23:47:00";
            Timer timer = new Timer();
            Date dateRef = sdf.parse(dateString);
            Updater updater = new Updater();
            updater.setRoot(root);
            updater.setAdminStuController(loader.getController());
            new Timer().schedule(updater,0,20000);
            stage.show();
        }catch (Exception e ){
            e.printStackTrace();
        }
    }
    class Updater extends TimerTask{
        private Parent root;
        private AdminStuController adminStuController;
        public Parent getRoot() {
            return root;
        }

        public void setRoot(Parent root) {
            this.root = root;
        }

        public AdminStuController getAdminStuController() {
            return adminStuController;
        }

        public void setAdminStuController(AdminStuController adminStuController) {
            this.adminStuController = adminStuController;
        }

        @Override
        public void run() {
            try {
                TableView tableView = (TableView) root.lookup("#adm_tblList_stu");
                adminStuController.update(tableView);
                System.out.println("定时更新!!");
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }


    public static void main(String[] args) {
        launch(args);
    }

}
